package com.union.core.family.model.dao.impl;


import java.sql.ResultSet;

import org.apache.log4j.Logger;

import com.hnjowe.webdb.DBOperation;
import com.union.core.family.model.Family_Personnel;
import com.union.core.family.model.dao.Family_PersonnelDao;





public class Family_PersonnelDaoImpl implements Family_PersonnelDao {
	private Family_Personnel family_Personnel; 
	private DBOperation opera;
	private static Logger log = Logger.getLogger(Family_PersonnelDaoImpl.class.getName());
	public Family_PersonnelDaoImpl(){
		
	}
	
	public boolean add(Family_Personnel family_Personnel){
		boolean result = false;
		try{
			opera = new DBOperation();
			opera.transcationBegin();
			String sql = "insert into family_personnel(family_head,family_idcard,family_phone,family_address,family_unit,"
					+ "family_position,family_birth,family_status,family_account,family_condition,family_subsidies,family_income,"
					+ "family_belongs,family_schooling,family_political,family_worktime,family_national,family_place,family_postal,"
					+ "family_awardshonor,family_sympathy,family_deeds,family_note) "
					+ "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ";
				 opera.prepStatment(sql);
				 opera.setString(1,family_Personnel.getFamily_head());
				 opera.setInt(2, family_Personnel.getFamily_idcard());
				 opera.setInt(3, family_Personnel.getFamily_phone());
				 opera.setString(4,family_Personnel.getFamily_address());
				 opera.setString(5,family_Personnel.getFamily_unit());
				 opera.setString(6,family_Personnel.getFamily_position());
				 opera.setString(7,family_Personnel.getFamily_birth());
				 opera.setInt(8,family_Personnel.getFamily_status());
				 opera.setInt(9,family_Personnel.getFamily_account());
				 opera.setInt(10, family_Personnel.getFamily_condition());
				 opera.setInt(11, family_Personnel.getFamily_subsidies());
				 opera.setInt(12, family_Personnel.getFamily_income());
				 opera.setString(13, family_Personnel.getFamily_belongs());
				 opera.setString(14, family_Personnel.getFamily_schooling());
				 opera.setString(15,family_Personnel.getFamily_political());
				 opera.setInt(16,family_Personnel.getFamily_worktime());
				 opera.setString(17, family_Personnel.getFamily_national());
				 opera.setString(18, family_Personnel.getFamily_place());
				 opera.setInt(19,family_Personnel.getFamily_postal());
				 opera.setString(20, family_Personnel.getFamily_awardshonor());
				 opera.setString(21, family_Personnel.getFamily_sympathy());
				 opera.setString(22,family_Personnel.getFamily_address());
				 opera.setString(23, family_Personnel.getFamily_note());
				 opera.execute();
				 result = opera.transcationCommit();
				 }catch(Exception e){
					 log.error(e);
				 }finally{
					 opera.closePres();
					 opera.closePres();			 
				 }
				 	return result;
	}
	
	public Boolean delete(int id){
		boolean result = false;
		try{
			opera = new DBOperation();
			opera.transcationBegin();
			String sql = "delete from family_personnel where id=? ";
			opera.prepStatment(sql);
			opera.setInt(1, id);
			opera.execute();
			result = opera.transcationCommit();
		}catch(Exception e){
			log.error(e);
		}finally{
			opera.closePres();
			opera.closeConn();
		}
		 return result;
	}
	
	public boolean edit(Family_Personnel family_Personnel){
		boolean result = false;
		try{
			opera = new DBOperation();
			opera.transcationBegin();
			String sql = "update family_personnel "
						+ "set family_head=?,family_idcard=?,family_phone=?,family_address=?,family_unit=?,"
						+ "family_position=?,family_birth=?,family_status=?,family_account=?,family_condition=?,"
						+ "family_subsidies=?,family_income=?,family_belongs=?,family_schooling=?,family_political=?,"
						+ "family_worktime=?,family_national=?,family_place=?,family_postal=?,family_awardshonor=?,"
						+ "family_sympathy=?,family_deeds=?,family_note=? "
						+ "where id=?";
			  opera.prepStatment(sql);
			  opera.setString(1,family_Personnel.getFamily_head());
				 opera.setInt(2, family_Personnel.getFamily_idcard());
				 opera.setInt(3, family_Personnel.getFamily_phone());
				 opera.setString(4,family_Personnel.getFamily_address());
				 opera.setString(5,family_Personnel.getFamily_unit());
				 opera.setString(6,family_Personnel.getFamily_position());
				 opera.setString(7,family_Personnel.getFamily_birth());
				 opera.setInt(8,family_Personnel.getFamily_status());
				 opera.setInt(9,family_Personnel.getFamily_account());
				 opera.setInt(10, family_Personnel.getFamily_condition());
				 opera.setInt(11, family_Personnel.getFamily_subsidies());
				 opera.setInt(12, family_Personnel.getFamily_income());
				 opera.setString(13, family_Personnel.getFamily_belongs());
				 opera.setString(14, family_Personnel.getFamily_schooling());
				 opera.setString(15,family_Personnel.getFamily_political());
				 opera.setInt(16,family_Personnel.getFamily_worktime());
				 opera.setString(17, family_Personnel.getFamily_national());
				 opera.setString(18, family_Personnel.getFamily_place());
				 opera.setInt(19,family_Personnel.getFamily_postal());
				 opera.setString(20, family_Personnel.getFamily_awardshonor());
				 opera.setString(21, family_Personnel.getFamily_sympathy());
				 opera.setString(22,family_Personnel.getFamily_address());
				 opera.setString(23, family_Personnel.getFamily_note());
				 opera.executeUpdate();
				 result = opera.transcationCommit();
		}catch(Exception e){
			log.error(e);
			opera.closePres();
			opera.closeConn();
		}
		return result;
	}
	
	public Family_Personnel query(int id){
		Family_Personnel family_Personnel=null;
		try{
			opera = new DBOperation();
			opera.transcationBegin();
			String sql = "select "
						+ "id,family_head,family_idcard,family_phone,family_address,family_unit,family_position,"
						+ "family_birth,family_status,family_account,family_condition,family_subsidies,family_income,"
						+ "family_belongs,family_schooling,family_political,family_worktime,family_national,family_place,"
						+ "family_postal,family_awardshonor,family_sympathy,family_deeds,family_note"
						+ " from family_personnel "
						+ " where id=?";
			 opera.prepStatment(sql);
			 opera.setInt(1, id);
			 ResultSet res = opera.executeQuery();
			 while(null!=res && res.next()){
				 family_Personnel = new Family_Personnel();
				 family_Personnel.setId(res.getInt(1));
				 family_Personnel.setFamily_head(res.getString(2));
				 family_Personnel.setFamily_idcard(res.getInt(3));
				 family_Personnel.setFamily_phone(res.getInt(4));
				 family_Personnel.setFamily_address(res.getString(5));
				 family_Personnel.setFamily_unit(res.getString(6));
				 family_Personnel.setFamily_position(res.getString(7));
				 family_Personnel.setFamily_birth(res.getString(8));
				 family_Personnel.setFamily_status(res.getInt(9));
				 family_Personnel.setFamily_account(res.getInt(10));
				 family_Personnel.setFamily_condition(res.getInt(11));
				 family_Personnel.setFamily_subsidies(res.getInt(12));
				 family_Personnel.setFamily_income(res.getInt(13));
				 family_Personnel.setFamily_belongs(res.getString(14));
				 family_Personnel.setFamily_schooling(res.getString(15));
				 family_Personnel.setFamily_political(res.getString(16));
				 family_Personnel.setFamily_worktime(res.getInt(17));
				 family_Personnel.setFamily_national(res.getString(18));
				 family_Personnel.setFamily_place(res.getString(19));
				 family_Personnel.setFamily_postal(res.getInt(20));
				 family_Personnel.setFamily_awardshonor(res.getString(21));
				 family_Personnel.setFamily_sympathy(res.getString(22));
				 family_Personnel.setFamily_deeds(res.getString(23));
				 family_Personnel.setFamily_note(res.getString(24));
			 }
			 
			 }catch(Exception e){
				 	log.error(e);
			 }finally{
				 opera.closePres();
				 opera.closeConn();
			 }
			  return family_Personnel;
		}	
		
	
}
